package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;

import com.elinkway.infinitemovies.async.MoviesHttpAsyncTask;
import com.elinkway.infinitemovies.async.RequestResultListener;
import com.elinkway.infinitemovies.bean.Channel;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.ChannelPieceParser;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by zhaopeipei on 2016/9/12.
 */
public class RequestPieceTask extends MoviesHttpAsyncTask<Channel> {

    RequestResultListener<Channel> mListener;

    public RequestPieceTask(Context context) {
        super(context);
    }

    @Override
    public LVideoDataHull<Channel> doInBackground() {
        return MoviesHttpApi.requestChannelPiece(new ChannelPieceParser());
    }

    @Override
    public void onPostExecute(int updateId, Channel result) {
        if(null != mListener){
            mListener.onRequestSuccess(updateId, result);
        }
    }

    @Override
    public void netNull() {
        super.netNull();
        if(null != mListener){
            mListener.onRequestFailed();
        }
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        super.netErr(updateId, errMsg);
        if(null != mListener){
            mListener.onRequestFailed();
        }
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
        if(null != mListener){
            mListener.onRequestFailed();
        }
    }

    public void setOnListener(RequestResultListener<Channel> listener) {
        mListener = listener;
    }

}
